package com.airy.highSpeed.controller;

import com.airy.highSpeed.entity.ExpresswayInfEntity;
import com.airy.highSpeed.service.ExpresswayInfService;
import com.airy.highSpeed.utils.PageUtils;
import com.airy.highSpeed.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author dingyakun
 * @email 821041490@qq.com
 * @date 2020-12-15 13:21:16
 */
@RestController
@RequestMapping("product/ei")
public class ExpresswayInfController {
    @Autowired
    private ExpresswayInfService expresswayInfService;

    /**
     * 查询所有
     */
    @RequestMapping("/findAll")
    public List<ExpresswayInfEntity> findAll(){
        return expresswayInfService.findAll();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = expresswayInfService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        ExpresswayInfEntity expresswayInfEntity = expresswayInfService.getById(id);

        return R.ok().put("expresswayInfEntity", expresswayInfEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ExpresswayInfEntity expresswayInfEntity){
		expresswayInfService.save(expresswayInfEntity);

        return R.ok();
    }

    /**
     * 批量修改
     */
    @RequestMapping("/update/sort")
    //@RequiresPermissions("product:category:update")
    public R updateSort(@RequestBody ExpresswayInfEntity[] expresswayInfEntities) {
        expresswayInfService.updateBatchById(Arrays.asList(expresswayInfEntities));
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ExpresswayInfEntity expresswayInfEntity){
		expresswayInfService.updateById(expresswayInfEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		expresswayInfService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询不为空
     */
    @RequestMapping("/findNotNull")
    public List<String> findTollStationIdNotNull(){
        return expresswayInfService.findTollStationIdNotNull();
    }

    public R updateByTollStationId(ExpresswayInfEntity expresswayInfEntity) {
        expresswayInfService.updateByTollStationId(expresswayInfEntity);
        return R.ok();
    }

    public ExpresswayInfEntity findExpresswayInfByTollStationId(String tollStationId) {
        return expresswayInfService.findExpresswayInfByTollStationId(tollStationId);
    }
}
